package net.huashitong.ssydt.provider.config;

import net.huashitong.ssydt.provider.intercetors.LogInterceptor;
import net.huashitong.ssydt.provider.security.interceptor.AuthenticationInterceptor;
import net.huashitong.ssydt.provider.security.interceptor.SignValidateInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 *
 */
@Configuration
public class InterceptorsConfiguration extends WebMvcConfigurerAdapter{

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(logInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/static/**");
        registry.addInterceptor(signValidateInterceptor())
                .addPathPatterns("/api/**")
                .excludePathPatterns("/static/**");
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/api/**")
                .excludePathPatterns("/static/**");
        super.addInterceptors(registry);
    }

    @Bean
    public LogInterceptor logInterceptor() {
        return new LogInterceptor();
    }

    @Bean
    public SignValidateInterceptor signValidateInterceptor() {
        return new SignValidateInterceptor();
    }

    @Bean
    public AuthenticationInterceptor authenticationInterceptor() {
        return new AuthenticationInterceptor();
    }

}
